package com.qqhf.hitfood.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qqhf.common.entity.AjaxResult;
import com.qqhf.common.entity.PageEntity;
import com.qqhf.hitfood.bean.core.BaseController;
import com.qqhf.hitfood.bean.entity.TypeShop;
import com.qqhf.hitfood.service.ITypeShopService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@Api(tags = "T - [字典]店铺分类")
@RestController
@RequestMapping("/type/shop")
public class TypeShopController extends BaseController {
    @Autowired
    private ITypeShopService typeShopService;

    @GetMapping("/page")
    public AjaxResult page(PageEntity pageEntity, TypeShop typeShop) {
        return AjaxResult.success(typeShopService.page(pageEntity.toPage(), Wrappers.lambdaQuery(typeShop)));
    }

    @GetMapping("/list")
    public AjaxResult list(TypeShop typeShop) {
        return AjaxResult.success(typeShopService.list(Wrappers.lambdaQuery(typeShop)));
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody TypeShop typeShop) {
        return AjaxResult.success(typeShopService.save(typeShop));
    }

    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody TypeShop typeShop) {
        return AjaxResult.success(typeShopService.updateById(typeShop));
    }

    @DeleteMapping("/delete/{ids}")
    public AjaxResult delete(@PathVariable Integer[] ids) {
        return AjaxResult.success(typeShopService.removeByIds(Arrays.asList(ids)));
    }

    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Integer id) {
        return AjaxResult.success(typeShopService.getById(id));
    }
}
